#include <stdio.h>
#include <pthread.h>

int gnum = 0;
pthread_mutex_t mutex;

void * func(void * arg){
    for(int i = 0;i <1000000;++i){
        pthread_mutex_lock(&mutex);
        ++gnum;
        pthread_mutex_unlock(&mutex);
    }
    return NULL;
}

int main()
{
    pthread_mutex_init(&mutex,NULL);
    
    pthread_t pthid1;
    pthread_create(&pthid1,NULL,func,NULL);
    pthread_t pthid2;
    pthread_create(&pthid2,NULL,func,NULL);
    
    pthread_join(pthid1,NULL);
    pthread_join(pthid2,NULL);
    printf("num = %d\n",gnum);
    return 0;
}

